package top.byteio.common.core.exception;

import com.alibaba.fastjson2.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serial;

/**
* 通用异常处理
* @author lerryxia
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class BaseCommonException extends RuntimeException{
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 应用名
     */
    private String moduleName;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误提示
     */
    private String message;

    /**
     * 错误明细
     */
    private String detailMessage;

    public BaseCommonException(String moduleName, String message) {
        this(moduleName, null, message, null);
    }

    public BaseCommonException(String moduleName, String message, Exception e) {
        this(moduleName,null,message, JSON.toJSONString(e));
    }
}
